package com.tanran.parse.service.impl;

import com.tanran.parse.service.ParseService;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * Created by Enzo Cotter on 2019/11/14.
 */
@Service
public class ParseServiceImpl implements ParseService {


    @Override
    public String parse(String id) {
        String content="";
       try {
           Document document= Jsoup.connect("http://new.juyifx.cn./detail/"+id+".html").timeout(10000).get();
           content=document.getElementsByClass("artcontent").html();
           Document doc = Jsoup.parse(content);
           Elements pngs = doc.select("img[alt]");
           for (Element png : pngs) {
               String alt = png.attr("alt");
               alt=alt.replace("惠小助","坦然活动 ").replace("new.juyifx.cn","");
               png.attr("alt", alt);
           }
           content = doc.toString();
       }catch (IOException e){
           e.printStackTrace();
       }
       return content;
    }

    public static void main(String[] args) {
        String parse = new ParseServiceImpl().parse("88213776");
        System.out.println(parse);
    }
}
